import { DailyWorkAT } from "../action-types";
import { DailyWorkAction } from "../actions/dailyWorkActions";

const initialState: string[] = [];

const dailyWorkReducer = (
  state: string[] = initialState,
  action: DailyWorkAction
) => {
  switch (action.type) {
    case DailyWorkAT.ADDDAILYTASK:
      state.push(action.task);
      return state;
    case DailyWorkAT.REMOVEDAILYTASK:
      state.splice(action.index, 1);
      return [...state];
    case DailyWorkAT.EDITDAILYTASK:
      state[action.index] = action.task;
      return state;
    default:
      return state;
  }
};

export default dailyWorkReducer;
